package com.example.arm.integration.lifecycle

import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

/**
 *  author : yanghaozhang
 *  date : 2020/9/22 16:45
 *  description :
 */
open class FragmentDelegate(protected var mFragment: Fragment?) : DefaultLifecycleObserver {

    init {
        if (mFragment is LifecycleOwner) {
            (mFragment as LifecycleOwner).lifecycle.addObserver(this)
        }
    }

    override fun onDestroy(owner: LifecycleOwner) {
        owner.lifecycle.removeObserver(this)
        onDestroyed(owner)
        mFragment = null
    }

    open fun onDestroyed(owner: LifecycleOwner) {

    }
}